<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
<head>
	<title>后台管理</title>
	<meta charset="utf-8">
	<link rel="stylesheet" type="text/css" href="/exchange/Public/css/bootstrap.min.css">
	<script type="text/javascript" src='/exchange/Public/js/jquery-3.1.1.min.js'></script>
	<script type="text/javascript" src='/exchange/Public/js/bootstrap.min.js'></script>
	<style type="text/css">
		#top{
			width: 100%;
			height: 40px;
			background-color: rgb(51,174,204);
		}
		#myTab li{
			float: left;
		}
		 ul.nav-tabs{
        width: 140px;
        margin-top: 20px;
        border-radius: 4px;
        border: 1px solid #ddd;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.067);
    }
    ul.nav-tabs li{
        margin: 0;
        border-top: 1px solid #ddd;
    }
    ul.nav-tabs li:first-child{
        border-top: none;
    }
    ul.nav-tabs li a{
        margin: 0;
        padding: 8px 16px;
        border-radius: 0;
    }
    ul.nav-tabs li.active a, ul.nav-tabs li.active a:hover{
        color: #fff;
        background: #0088cc;
        border: 1px solid #0088cc;
    }
    ul.nav-tabs li:first-child a{
        border-radius: 4px 4px 0 0;
    }
    ul.nav-tabs li:last-child a{
        border-radius: 0 0 4px 4px;
    }
    ul.nav-tabs.affix{
        top: 30px; /* Set the top position of pinned element */
    }
	</style>
</head>
<body>
	<nav class="navbar navbar-default" role="navigation" id="top"> 
    <div class="container-fluid"> 
        <div class="navbar-header"> 
            <a class="navbar-brand" href="#" style="color: white">后台管理</a> 
        </div> 
        <ul class="nav navbar-nav navbar-right"> 
            <li><a href="/exchange" style="color: white" id="home"><span class="glyphicon glyphicon-home"></span>&nbsp;&nbsp;返回主页</a></li> 
            <li><a href="#" style="color: white">超级管理员</a></li> 
            <li><a href="#" style="color: white"><span class="glyphicon glyphicon-log-in" ></span>&nbsp;&nbsp;<?php echo ($user); ?></a></li> 
        </ul> 
    </div> 
</nav>
<div class="container">
    <div class="row">
        <div class="col-xs-3" id="myScrollspy">
            <ul class="nav nav-tabs nav-stacked" id="myNav">
                <li class="active"><a href="#section-1">账户管理</a></li>
                <li><a href="#section-2">商品管理</a></li>
            </ul>
        </div>
        <div class="col-xs-9">
            <div id="section-1">
            	<h2>账户列表</h2>
            	<table class="table table-bordered">
						<thead>
							<tr>
								<th>id</th>
								<th>用户名</th>
								<th>状态</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
                        <?php if(is_array($data_user)): foreach($data_user as $key=>$val): ?><tr>
                                  <td><?php echo ($val["id"]); ?></td>
                                  <td><?php echo ($val["username"]); ?></td>
                                  <td class="status"><?php echo ($val["status"]); ?></td>
                                  <td><button type="button" class="btn btn-danger del">删除</button>
                              </tr><?php endforeach; endif; ?>
						</tbody>
				</table>
              <h2>删除账户管理</h2>
         <table class="table table-bordered">
            <thead>
              <tr>
                <th>id</th>
                <th>用户名</th>
                <th>状态</th>
                <th>操作</th>
              </tr>
            </thead>
            <tbody>
                    <?php if(is_array($del_user)): foreach($del_user as $key=>$val): ?><tr>
                              <td><?php echo ($val["id"]); ?></td>
                              <td><?php echo ($val["username"]); ?></td>
                              <td><?php echo ($val["status"]); ?></td>
                               <td><button type="button" class="btn btn-info back">撤回</button>
                        </tr><?php endforeach; endif; ?>
            </tbody>
        </table>
                <h2>添加账户</h2>
                <form class="form-horizontal" role="form">
                      <div class="form-group">
                        <label for="firstname" class="col-sm-2 control-label">用户名</label>
                        <div class="col-sm-4">
                          <input type="text" class="form-control" placeholder="4-16位" name="a_user">
                        </div>
                      </div>
                      <div class="form-group">
                        <label for="lastname" class="col-sm-2 control-label">密码</label>
                        <div class="col-sm-4">
                          <input type="password" class="form-control" name="a_pwd">
                        </div>
                      </div>
                      <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-4">
                          <button type="button" class="btn btn-success add">添加</button>
                        </div>
                      </div>
                    </form>
                    <h2>重置密码</h2>
                <form class="form-horizontal" role="form">
                      <div class="form-group">
                        <label for="firstname" class="col-sm-2 control-label">用户名</label>
                        <div class="col-sm-4">
                          <input type="text" class="form-control" placeholder="4-16位" name="r_user">
                        </div>
                      </div>
                      <div class="form-group">
                        <label for="lastname" class="col-sm-2 control-label">密码</label>
                        <div class="col-sm-4">
                          <input type="password" class="form-control" name="r_pwd">
                        </div>
                      </div>
                      <div class="form-group">
                        <label for="lastname" class="col-sm-2 control-label">再次输入密码</label>
                        <div class="col-sm-4">
                          <input type="password" class="form-control" name="r_pwd2">
                        </div>
                      </div>
                      <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-4">
                          <button type="button" class="btn btn-warning reset">重置</button>
                        </div>
                      </div>
                    </form>
            </div>
          
            <hr>
            
             <div id="section-2">
               <h2>商品管理</h2>
                 
                  <form class="form-inline" role="form">
                      <div class="form-group">
                        <label class="control-label" for="name">请输入发布者的名称</label>&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="text" class="form-control" name='product_user' placeholder="请输入名称" style="width: 300px;">
                      </div>
                      <label class="checkbox-inline">
                          <input type="radio" name="optionsRadiosinline" id="optionsRadios3" value="ershou" checked>二手精品
                      </label>
                      <label class="checkbox-inline">
                          <input type="radio" name="optionsRadiosinline" id="optionsRadios4" value="qiugou">求购信息
                      </label>
                      <label class="checkbox-inline">
                          <input type="radio" name="optionsRadiosinline" id="optionsRadios4" value="jiaohuan">以物换物
                      </label>
                      &nbsp;&nbsp;&nbsp;&nbsp;
                      <button type="button" class="btn btn-info product_show">提交</button>
                </form>
               <table class="table table-bordered">
                     <thead>
                         <tr>
                             <td>id</td>
                             <td>用户名</td>
                             <td>产品种类</td>
                             <td>产品描述</td>
                             <td>操作</td>
                         </tr>
                     </thead>
                     <tbody id="product_data">
                     
                     </tbody>
             </table> 

             </div>
            <hr>
        </div>
    </div>
</div>
</body>
</html>
<script type="text/javascript">

$('.product_show').click(function(){
    $user=$('input[name=product_user]').val();
    $option=$("input[type='radio']:checked").val();
   /* alert($option);*/
    $.ajax({
        url:'<?php echo U("Admin/Index/getproduct");?>',
        type:"POST",
        data:{user:$user,option:$option},
        dataType:"json",
        success:function(data){
            $str="";
            for(var i=0;i<data.length;i++){
$str+="<tr><td>"+data[i].id+"</td><td>"+data[i].user+"</td><td>"+data[i].kind+"</td><td>"+data[i].desc+"</td><td><button type='button' class='btn btn-danger del_product'>删除</button></td></tr>";
            }
            $("#product_data").html($str);
        }
    })
})

$("#product_data").on("click",".del_product",function(){
    $id=$(this).parent().prev().prev().prev().prev().text();
    $option=$("input[type='radio']:checked").val();
    $.ajax({
        url:"<?php echo U('Admin/Index/delproduct');?>",
        data:{id:$id,option:$option},
        type:"POST",
        success:function(data){
              if(data==1){
                window.location.reload();
            }else{
                alert('删除失败');
            }
        }
    })
})
$(function(){
   $(".status").each(function(){
       if($(this).text()==1){
          $(this).parent().css('display','none');
       }
   });
})
    $(".del").click(function(){
        $id=$(this).parent().prev().prev().prev().text();
        $.ajax({
            url:'<?php echo U("Admin/index/del");?>',
            data:{id:$id},
            type:'POST',
            success:function(data){
              window.location.reload();
            }
        });
    })
    $('.back').click(function(){
         $id=$(this).parent().prev().prev().prev().text();
        $.ajax({
            url:'<?php echo U("Admin/index/back");?>',
            data:{id:$id},
            type:'POST',
            success:function(data){
              window.location.reload();
            }
        });
    })
    $('.add').click(function(){
        $user=$('input[name=a_user]').val();
        $pwd=$('input[name=a_pwd]').val();
        $.ajax({
            url:'<?php echo U("Admin/index/add");?>',
            data:{user:$user,pwd:$pwd},
            type:'POST',
            success:function(data){
            if(data==1){
                window.location.reload();
            }else{
                alert('用户名已存在');
                $('input[name=a_user]').val("");
                $('input[name=a_pwd]').val('');
            }
            }
        })

    })
    $('input[name=r_user]').blur(function(){
        $.ajax({
            url:'<?php echo U("Admin/index/isExist");?>',
            data:{user:$(this).val()},
            type:'POST',
            success:function(data){
                if(data==0){
                    alert('用户名不存在');
                    $('input[name=r_user]').val('');
                }else{
                    return true;
                }
            }
        })
    })
    $("input[name=r_pwd2]").blur(function(){
        if($(this).val()!=$('input[name=r_pwd]').val()){
               alert('两次密码不一致');
               $('input[name=r_pwd]').val('');
               $('input[name=r_pwd2]').val('');
        }else{
              return true;
        }
    })
    $(".reset").click(function(){
        $r_user=$('input[name=r_user]').val();
        $r_pwd=$('input[name=r_pwd]').val();
        $.ajax({
            url:'<?php echo U("Admin/index/reset");?>',
            data:{r_user:$r_user,r_pwd:$r_pwd},
            type:"POST",
            success:function(data){
                if (data==0) {
                    alert('重置失败');
                }else{
                    window.location.reload();
                }
            }
        })
    })

</script>